package com.longdaji.decoration.ui.main;

import android.util.Log;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.bean.GoodsCategory;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by longtao on 2017/12/19.
 */

public class MainPresenter extends RxPresenter<MainContract.View> implements MainContract.Presenter {
    private final static String TAG = MainPresenter.class.getSimpleName();
    private DataManager mDataManager;

    @Inject
    public MainPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }


    @Override
    public void getGoodsCatergory() {
        addSubscribe(mDataManager.getGoodsCatergory()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtil.<GoodsCategory>handleResult())
                .subscribeWith(new CommonSubscriber<GoodsCategory>() {

                    @Override
                    public void onSuccess(GoodsCategory goodsCatergory) {
                        Log.d(TAG, "success,goods detail is " + goodsCatergory.toString());
                        if (mView == null) {
                            return;
                        }
                    }

                    @Override
                    public void onFailed(String msg) {
                        Log.d(TAG, "msg is " + msg);
                        if (mView != null) {
                            mView.toast(msg);
                        }
                    }
                }));

    }
}
